<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>血糖信息</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<!--<el-button type="primary" @click="openSugarInfo(null)">添 加</el-button>-->
				<el-table :data="sugarInfos" border highlight-current-row style="width: 100%">
					<!-- -->
					<el-table-column prop="sugarUserId" label="记录人">
						<template slot-scope="scope">
							{{scope.row.account.accountNick}}
						</template>
					</el-table-column>
					<el-table-column prop="sugarDate" label="日期"></el-table-column>
					<el-table-column prop="sugarValue" label="血糖值"></el-table-column>
					<el-table-column prop="sugarTime" label="时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<!--<el-button @click="openSugarInfo(scope.row)" type="text" size="small">修 改</el-button>-->
							<el-popconfirm title="是否删除？" @confirm="delSugarInfo(scope.row.sugarId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="sugarInfoForm.ttitle" :visible.sync="sugarInfoForm.visible" width="30%">
			<el-form :model="sugarInfoForm" :rules="sugarInfoRules" ref="sugarInfoForm" label-width="100px">
				<!-- -->
				<el-form-item label="记录人" prop="sugarUserId">
					<el-input v-model="sugarInfoForm.sugarUserId"></el-input>
				</el-form-item>
				<el-form-item label="日期" prop="sugarDate">
					<el-input v-model="sugarInfoForm.sugarDate"></el-input>
				</el-form-item>
				<el-form-item label="血糖值" prop="sugarValue">
					<el-input v-model="sugarInfoForm.sugarValue"></el-input>
				</el-form-item>
				<el-form-item label="时间" prop="sugarTime">
					<el-input v-model="sugarInfoForm.sugarTime"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeSugarInfo">取 消</el-button>
				<el-button type="primary" @click="saveSugarInfo">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		sugarInfos: [],
		selectSugarInfo: null,
		sugarInfoForm: {
			visible: false,
			ttitle: '新增/修改',
			sugarId : '',
			sugarUserId : '',
			sugarDate : '',
			sugarValue : '',
			sugarTime : '',
		},
		sugarInfoQuery: {
			page: '',
			size: '',
		},
		sugarInfoRules: {
			sugarId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			sugarUserId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			sugarDate: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			sugarValue: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			sugarTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getSugarInfos() {
			let that = this
			postRequst('/admin/getSugars', that.sugarInfoQuery, true).then(function (resp) {
				that.sugarInfos = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectSugarInfo = resp.rows[0]
				}
			})
		},
		openSugarInfo(row) {
			let that = this
			if (row) {
				that.sugarInfoForm.ttitle = '修改'
				that.sugarInfoForm.sugarId = row.sugarId
				that.sugarInfoForm.sugarUserId = row.sugarUserId
				that.sugarInfoForm.sugarDate = row.sugarDate
				that.sugarInfoForm.sugarValue = row.sugarValue
				that.sugarInfoForm.sugarTime = row.sugarTime
			} else {
				that.sugarInfoForm.ttitle = '新增'
				that.sugarInfoForm.sugarId = ''
				that.sugarInfoForm.sugarUserId = ''
				that.sugarInfoForm.sugarDate = ''
				that.sugarInfoForm.sugarValue = ''
				that.sugarInfoForm.sugarTime = ''
			}
			that.sugarInfoForm.visible = true
		},
		closeSugarInfo() {
			this.$refs["sugarInfoForm"].resetFields();
			this.sugarInfoForm.visible = false
		},
		saveSugarInfo() {
			let that = this
			this.$refs["sugarInfoForm"].validate((valid) => {
				if (valid) {
					postRequst('/admin/saveSugarInfo', that.sugarInfoForm).then(function (resp) {
						if (resp.status == 0) {
							that.getSugarInfos()
							that.sugarInfoForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delSugarInfo(sugarId) {
			let that = this
			postRequst('/admin/delSugarInfo', {sugarId: sugarId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getSugarInfos()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getSugarInfos()
	}
</script>

</html>